<?php
namespace Wechat\Controller;
use Think\Controller;
class OauthController extends Controller {
    
    public function index() {
            
            $openid = I('cookie.openid');
            
            $userInfo =  M('User')->where("openid = '" . $openid . "'")->find();
            
            if(!isNullOrEmpty($openid)) {
                $data['uid'] = $userInfo['uid'];
            } else {
                $data['uid'] = null;
            }
            
            $callback = I('post.callback');

            $url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' . C('appid') . '&redirect_uri=http://' . $_SERVER['HTTP_HOST'] . '/Wechat/Api/auth3/&response_type=code&scope=snsapi_userinfo&state=' . urlencode($callback) . '&connect_redirect=1#wechat_redirect';
            
            $data['url'] = $url;
            
            echo json_encode($data);
            
        }
    
}